The package nat.nblast implements the NBLAST neuron similarity algorithm described in Costa et al. 2016.

Using NBLAST to assess neuron similarity

NBLAST can be used to assess the similarity between neurons. In this example, NBLAST is used to compare a neuron drawn from a light-level tracing and a neuron drawn from an EM reconstruction (plotted in black and blue, respectively).

neuronTracing <- read.neuron('data/registeredNeuron_JFRC2013.swc',class="neuron")
A2_EM<- read.neuron('data/DNa02_01_09_2020.swc')
neuronEM<- xform_brain(A2_EM,sample=FAFB, reference = JFRC2013)

#plot both neurons 
open3d(userMatrix=rotationMatrix,windowRect=windowRect,zoom=0.6)
plot3d(neuronTracing,lwd=3,col='black',WithNodes=FALSE)
plot3d(neuronEM,lwd=3,col='blue',WithNodes=FALSE)
plot3d(JFRC2013)

You must enable Javascript to view this page properly.

all_neurons=neuronlist(neuronTracing,neuronEM)
nblast_scores=nblast_allbyall(all_neurons,smat = NULL, distance = FALSE)
## more than 1 point in .CleanupParentArray, choosing first from: 2 3more than 1 point in .CleanupParentArray, choosing first from: 2 3more than 1 point in .CleanupParentArray, choosing first from: 2 3more than 1 point in .CleanupParentArray, choosing first from: 2 3more than 1 point in .CleanupParentArray, choosing first from: 2 3more than 1 point in .CleanupParentArray, choosing first from: 2 3more than 1 point in .CleanupParentArray, choosing first from: 2 3more than 1 point in .CleanupParentArray, choosing first from: 2 3
##               neuronTracing  neuronEM
## neuronTracing     1.0000000 0.6352001
## neuronEM          0.5026174 1.0000000

Using NBLAST to find flycircuit clones

NBLAST can also be used to query databases of neurons based on similarity to your neuron of interest.

First, load in your neuron of interest

g13 <- read.neuron('data/g13_JFRC2013.swc',class="neuron")
open3d(userMatrix=rotationMatrix,windowRect=windowRect,zoom=0.6)
plot3d(g13,lwd=3,col='black',WithNodes=FALSE)
g13_JFRC2=xform_brain(g13,sample=JFRC2013,reference=JFRC2)

You must enable Javascript to view this page properly.

To find flycircuit clones,download the flycircuit data and convert it to a dotprops object(this takes a while but only needs to be done once )

fc_download_data('http://flybrain.mrc-lmb.cam.ac.uk/si/nblast/flycircuit/allbyallblastcv4.5.ff',
                 type='ff')
options('flycircuit.scoremat'="allbyallblastcv4.5.ff")
dps<-read.neuronlistfh("http://flybrain.mrc-lmb.cam.ac.uk/si/nblast/flycircuit/dpscanon.rds",
                       localdir=getOption('flycircuit.datadir'))
options('nat.default.neuronlist'='dps')
if(!require("devtools")) install.packages("devtools")
devtools::source_gist("bbaf5d53353b3944c090", filename = "FlyCircuitStartupNat.R")
dpscanon=read.neurons(dps)

Next, register your neuron to the FCWB template brain (the template brain space to which the flycircuit neurons are registered). If you want to search for bilateral hits, mirror your neuron about the y-axis of the FCWB template brain Convert this registered neuron to a dotprops object.

#transform brain into FCWB template space 
g13_FCWB=xform_brain(g13_JFRC2,sample=JFRC2,reference=FCWB)
g13_FCWB_mirror=mirror_brain(g13_FCWB,brain=FCWB)

#plot the neuron and its mirrored version 
open3d(userMatrix=rotationMatrix,windowRect=windowRect,zoom=0.6)
plot3d(g13_FCWB,lwd=3,col='black',WithNodes=FALSE)
plot3d(g13_FCWB_mirror,lwd=3,col='black',WithNodes=FALSE)

#convert neuron to dotprops object 
g13_dotprops=dotprops(c(g13_FCWB,g13_FCWB_mirror))

You must enable Javascript to view this page properly.

Finally, call nbast with your neuron and the flycircuit data as inputs

nblast_fc=nblast(g13_dotprops,target = dpscanon, normalised = TRUE);

#display top 10 hits 
nblast_fc_df=data.frame(name=names(nblast_fc),score=as.numeric(nblast_fc))
nblast_fc_df[order(-nblast_fc_df$score),][1:10,]
##                             name     score
## 16075      DvGlutMARCM-F554_seg1 0.4138000
## 660      FruMARCM-M001871_seg001 0.4086811
## 645      FruMARCM-M001857_seg001 0.3991717
## 15289     DvGlutMARCM-F1739_seg1 0.3987831
## 3683     FruMARCM-F002193_seg001 0.3977799
## 4737     FruMARCM-F002081_seg001 0.3791602
## 6321     FruMARCM-F001499_seg001 0.3781763
## 7903  DvGlutMARCM-F003769_seg001 0.3779877
## 440      FruMARCM-M001554_seg001 0.3759040
## 12912     DvGlutMARCM-F2008_seg1 0.3645502

Using NBLAST to find Gal4 lines

To find Gal4 lines similar to your neuron of interest, first download the Gal4 data. This takes a while but only needs to be done once. (Note: this database contains only GMR lines)

gmrdps<-read.neuronlistfh("http://flybrain.mrc-lmb.cam.ac.uk/si/nblast/gmrdps/gmrdps.rds",
                          localdir=getOption('flycircuit.datadir'))

Next, register your neuron to the FCWB template brain (the template brain space to which the Gal4 line data is registered). If you want to search for bilateral hits, mirror your neuron about the y-axis of the FCWB template brain Convert this registered neuron to a dotprops object.

#transform brain into FCWB template space 
g13_FCWB=xform_brain(g13_JFRC2,sample=JFRC2,reference=FCWB)
g13_FCWB_mirror=mirror_brain(g13_FCWB,brain=FCWB)

#plot the neuron and its mirrored version 
open3d(userMatrix=rotationMatrix,windowRect=windowRect,zoom=0.6)
plot3d(g13_FCWB,lwd=3,col='black',WithNodes=FALSE)
plot3d(g13_FCWB_mirror,lwd=3,col='black',WithNodes=FALSE)

#convert neuron to dotprops object 
g13_dotprops=dotprops(c(g13_FCWB,g13_FCWB_mirror))

You must enable Javascript to view this page properly.

Finally, call nbast with your neuron and the Gal4 data as inputs

nblast_gal4=nblast(g13_dotprops,target = gmrdps, normalised = TRUE);

#display 10  hits
nblast_gal4_df=data.frame(name=names(nblast_gal4),score=as.numeric(nblast_gal4))
nblast_gal4_df[order(-nblast_gal4_df$score),][1:10,]
##       name     score
## 1528 48B06 0.5493086
## 440  20E07 0.5228161
## 995  33H03 0.5018963
## 1643 50E11 0.4532963
## 2500 74C11 0.4454849
## 486  21C11 0.4421991
## 623  24C06 0.4376393
## 1179 38H03 0.4304561
## 2524 74G09 0.4297921
## 863  30E02 0.4213147